<?php

/************************
* SECURITY CHECK
************************/
if (!defined('PUBLIC_HTML'))
{
	exit;
}

/************************
* TEMPLATE PREPATIONS
************************/
$tpl_content = new TemplatePower(PATH_HTML . 'prices_body' . EXT_HTML);
$tpl_content->prepare();

$tpl_content_vars = array(
	'PAGE_TITLE'	=> $page_title,
	'PAGE_CONTENT'	=> $page_content,
);

$tpl_content->assign($tpl_content_vars);

/************************
* GET CONFIGURATIONS
************************/
$c_prices					= array();
$c_prices['cat_orderby']	= (preg_match('/(cat_id|cat_title)/', $config->get('prices_cat_orderby'))) ? $config->get('prices_cat_orderby') : 'cat_title';
$c_prices['cat_ordertype']	= (preg_match('/(ASC|DESC)/', $config->get('prices_cat_ordertype'))) ?  $config->get('prices_cat_ordertype') : 'ASC';
$c_prices['pri_orderby']	= (preg_match('/(pri_id|pri_title|pri_price)/', $config->get('prices_orderby'))) ? $config->get('prices_orderby') : 'pri_title';
$c_prices['pri_ordertype']	= (preg_match('/(ASC|DESC)/', $config->get('prices_ordertype'))) ?  $config->get('prices_ordertype') : 'ASC';

/************************
* GET CATEGORIES FROM DATABASE
************************/
$get_categories =	"
					SELECT		*
					FROM		" . TABLE_CATEGORIES . "
					WHERE		cat_type = '" . CAT_PRICES . "'
					ORDER BY	" . $c_prices['cat_orderby'] . "
					" . $c_prices['cat_ordertype'] . "
					";
$sql_categories =	$db->sql_query($get_categories);
while($row_categories = $db->sql_fetch_assoc($sql_categories))
{
	$category_id	= (int) 	$row_categories['cat_id'];
	$category_title	= (string) 	$row_categories['cat_title'];
	$tpl->newblock("GET CATEGORIES");
	$tpl_content->assign(array(
		'CAT_ID'	=> $category_id,
		'CAT_TITLE'	=> $category_title
	));
	
/************************
* GET PRICES FROM DATABASE
************************/
	$get_prices		= 	"
						SELECT		*
						FROM		" . TABLE_PRICES . "
						WHERE		pri_active = '1'
						AND			pri_cat_id = '" . $category_id . "'
						ORDER BY	" . $c_prices['pri_orderby'] . "
						" . $c_prices['pri_ordertype'] . "
						";
	$sql_prices		= $db->sql_query($get_prices);
	while ($row_prices = $db->sql_fetch_assoc($sql_prices))
	{
		$price_title	= (string)	$row_prices['pri_title'];
		$price_price	= (int)		$row_prices['pri_price'];
		$tpl->newBlock("GET PRICES");
		$tpl_content->assign(array(
			'PRICE_TITLE'	=> $price_title,
			'PRICE_PRICE'	=> $price_price
		));
	}
}

?>